{extend name="Base" /}
{block name="title"}{$title}{/block}
{block name="body"}
<fieldset class="layui-elem-field layui-field-title">
	<legend>{$name}</legend>
</fieldset>

<form class="layui-form layui-form-pane">
	<div class="layui-form-item">
		<label class="layui-form-label">SMTP地址</label>
		<div class="layui-input-inline">
			<input type="text" name="host" lay-verify="required" placeholder="SMTP发件服务器地址" autocomplete="off" class="layui-input" value="{$smtp.host}">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">邮箱帐号</label>
		<div class="layui-input-inline">
			<input type="text" name="username" lay-verify="required" placeholder="发件帐号" autocomplete="off" class="layui-input" value="{$smtp.username}">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">邮箱密码</label>
		<div class="layui-input-inline">
			<input type="text" name="password" lay-verify="required" placeholder="发件帐号的密码" autocomplete="off" class="layui-input" value="{$smtp.password}">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">SSL</label>
		<div class="layui-input-inline">
			{if condition="empty($smtp.secureprotocol)"}
			<input type="checkbox" name="secureprotocol" lay-skin="switch" lay-text="开启|关闭" placeholder="" value="ssl">
			{else /}
			<input type="checkbox" name="secureprotocol" lay-skin="switch" lay-text="开启|关闭" placeholder="" value="ssl" checked>
			{/if}
		</div>
		<div class="layui-form-mid layui-word-aux">是否开启加密发件</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">端口</label>
		<div class="layui-input-inline">
			<input type="text" name="port" lay-verify="required" placeholder="发件端口号" autocomplete="off" class="layui-input" value="{$smtp.port}">
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-input-inline">
			<button class="layui-btn" lay-submit="" lay-filter="submit">提交</button>
		</div>
	</div>
</form>

<script>
	layui.use(['form', 'layer'], function () {
		var form = layui.form;
		var layer = layui.layer;

		//监听提交
		form.on('submit(submit)', function (data) {
			var str = data.field;
			$.ajax({
				type: "POST",
				url: "/backend/system/doSmtp",
				cache: false,
				data: str,
				dataType: "json",
				success: function (e) {
					if (e.status === 1) {
						layer.alert(e.message, {
							//成功图标
							icon: 1
						});
					} else if (e.status === 0) {
						layer.alert(e.message, {
							//失败图标
							icon: 2
						});
					} else {
						layer.alert("系统错误，请稍后重试", {
							//失败图标
							icon: 2
						});
					}
				}
			});
			return false;
		});
	});
</script>
{/block}